<!--弹出省省市-->
<div class="provinceCityAll">
<%@ page language="java" pageEncoding="UTF-8"%>
<link rel="stylesheet" href="${baseURL}/css/area/cityLayout.css"/>
	<div class="tabs clearfix">
		<ul>
			<li><a href="javascript:" class="current" tb="hotCityAll">热门城市</a></li>
			<li><a href="javascript:" tb="provinceAll">省份</a></li>
			<li><a href="javascript:" tb="cityAll" id="cityAll">城市</a></li>
			<li><a href="javascript:" tb="countyAll" id="countyAll">区县</a></li>
		</ul>
	</div>
	
	<div class="con">
		<div class="hotCityAll invis">
			<div class="pre"><a></a></div>
			<div class="list">
				<ul></ul>
			</div>
			<div class="next"><a class="can"></a></div>
		</div>
		<div class="provinceAll invis">
			<div class="pre"><a><</a></div>
			<div class="list">
				<ul></ul>
			</div>
			<div class="next"><a class="can">></a></div>
		</div>
		<div class="cityAll invis">
			<div class="pre"><a><</a></div>
			<div class="list">
				<ul></ul>
			</div>
			<div class="next"><a class="can">></a></div>
		</div>
		<div class="countyAll invis">
			<div class="pre"><a><</a></div>
			<div class="list">
				<ul></ul>
			</div>
			<div class="next"><a class="can">></a></div>
		</div>
	</div>
</div>
<script>
	$(".provinceAll .pre a").bind('click',function() {
		var provincePage1 = parseInt($('#provincePage1').html());
		if (provincePage1 == 1) {
			return;
		}
		viewAllProvince(provincePage1 - 1);
	});
	
	$(".cityAll .pre a").bind('click',function() {
		var cityPages1 = parseInt($('#cityPage1').html());
		if (cityPages1 == 1) {
			return;
		}
		allCityPage(cityPages1 - 1);
	});
	$(".countyAll .pre a").bind('click',function() {
		var countyPages = parseInt($('#countyPage1').html());
		if (countyPages == 1) {
			return;
		}
		allCountyPage(countyPages - 1);
	});
	$(".provinceAll .next a").bind('click',	function() {
		var provincePage1 = parseInt($('#provincePage1').html());
		provinceAllTotalPage = countAllProvincePages();
		if (provincePage1 >= provinceAllTotalPage) {
			return;
		}
		viewAllProvince(provincePage1 + 1);
	});
	$(".cityAll .next a").bind('click',	function() {
		if ($(this).hasClass("can")) {
			var cityPages1 = parseInt($('#cityPage1').html());
			allCityPage(cityPages1 + 1);
		}
	});
	$(".countyAll .next a").bind('click',function() {
		if ($(this).hasClass("can")) {
			var countyPages = parseInt($('#countyPage1').html());
			allCountyPage(countyPages + 1);
		}
	});
	
	var allProvinces = null;
	var allCities = null;
	var allAreas = null;
	var allProId = null;
	var cityIdAll = null;
	var provinceAllTotalPage = null;
	var pa_pageSize = 12;
	var pa_currentPage = 1;
	function sendAllProvinceAjax() {
		$.ajax({
			type: "get",
			url: baseURL+'/js/area/queryAllProvinces.js',
			async: false,
			dataType: "json",
			success: function(data) {
				allProvinces = data.provinces;
				provinceAllTotalPage = Math.ceil(allProvinces.length / pa_pageSize);
				$("body").data("allProvinces", allProvinces);
				viewAllProvince(1);
			},
			error: function(XMLHttpRequest, textStatus, errorThrown)
			 {
				$.ligerDialog.warn(textStatus);
			}
		});
	}
	function sendAllCitiesAjax() {
		$.ajax({
			type: "get",
			url: baseURL+'/js/area/queryCities.js',
			async: false,
			dataType: "json",
			success: function(data) {
				allCities = data.cities;
				$("body").data("CitysAll", data);
				viewAllHotCities();
			},
			error: function(XMLHttpRequest, textStatus, errorThrown)
			 {
				$.ligerDialog.warn(textStatus);
			}
		});
	}
	function sendAllCountiesAjax()
	 {
		$.ajax({
			type: "get",
			url: baseURL+"/js/area/queryAllAreas.js",
			async: false,
			dataType: "json",
			success: function(data) {
				allAreas = data.areas;
				$("body").data("allCountys", data.areas);
			},
			error: function(XMLHttpRequest, textStatus, errorThrown)
			 {
				$.ligerDialog.warn("网络繁忙，请稍后再试！");
			}
		});
	}
	function viewAllHotCities() {
		$(".hotCityAll .list ul").children().remove();
		$.each(allCities,
		function(i, city) {
			if (city.hotCity) {
				$(".hotCityAll .list ul").append("<li><a><input type='button' style='background:none;border:0px;cursor: pointer;' onclick=hotCityAddrInputAll(\'" + city.provinceId + "," + city.id + "," + city.name + "\') id='" + city.id + "' value='" + city.name + "'></a></li>");
			}
		});
	}
	function json2str(o) {
		var arr = [];
		var fmt = function(s) {
			if (typeof s == 'object' && s != null) return json2str(s);
			return /^(string|number)$/.test(typeof s) ? "'" + s + "'": s;
		};
		for (var i in o) arr.push("'" + i + "':" + fmt(o[i]));
		return '{' + arr.join(',') + '}';
	}
	function countAllProvincePages() {
		provinceAllTotalPage = Math.ceil(allProvinces.length / pa_pageSize);
		return provinceAllTotalPage;
	}
	function viewAllProvince(page) {
		$(".provinceAll .list ul li").remove();
		if (page == 1) {
			$(".provinceAll .pre a").removeClass("can");
			$(".provinceAll .next a").addClass("can");
		} else {
			$(".provinceAll .pre a").addClass("can");
			$(".provinceAll .next a").addClass("can");
		}
		var end;
		var start;
		if (page == provinceAllTotalPage) {
			start = (page - 1) * pa_pageSize;
			end = allProvinces.length;
			$(".provinceAll .next a").removeClass("can");
		} else {
			start = (page - 1) * pa_pageSize;
			end = start + pa_pageSize;
		}
		for (var i = start; i < end; i++) {
			var p_id = allProvinces[i].id;
			var p_name = allProvinces[i].provinceName;
			if (allProvinces[i].provinceName == '内蒙古自治区') {
				p_name = '内蒙古';
			} else if (allProvinces[i].provinceName == '黑龙江省') {
				p_name = '黑龙江';
			} else {
				p_name = allProvinces[i].provinceName.substr(0, 2);
			}
			var li = $('<li><a style="background: none repeat scroll 0% 0% transparent; border: 0px none;" href="javascript:onclick=viewAllCities(' + i + ');" id="' + p_id + '">' + p_name + '</a></li>');
			$(".provinceAll .list ul").append(li);
		}
		$(".provinceAll .list #provincePage1").remove();
		$(".provinceAll .list").append("<label id='provincePage1' style='display:none;'>" + page + "</label>");
	}
	function viewAllCities(i) {
		allProId = allProvinces[i].id;
		$("body").data("pAllName", allProvinces[i].provinceName);
		$("body").data("pAllId", allProId);
		allCitys = [];
		var j = 0;
		$.each(allCities,
		function(i, city) {
			if (city.provinceId == allProId) {
				allCitys[j++] = city;
			}
		});
		allCityTotalPage = Math.ceil(allCitys.length / pa_pageSize);
		$(".provinceCityAll").find(".tabs").find("a").removeClass("current");
		$(".provinceCityAll .tabs").find("#cityAll").addClass("current");
		$(".con .provinceAll .list a").removeClass("current");
		$(".con .provinceAll .list a[id='" + allProId + "']").addClass("current");
		$(".provinceCityAll").find(".con").children().hide();
		$(".provinceCityAll").find(".con").find(".cityAll").show();
		allCityPage(1);
	}
	function allCityPage(page) {
		$(".cityAll .list ul li").empty();
		$(".cityAll .list ul li").remove();
		if (page == 1) {
			$(".cityAll .pre a").removeClass("can");
		} else {
			$(".cityAll .pre a").addClass("can");
		}
		var start;
		var end;
		if (page <= 1) {
			page = 1;
			$(".cityAll .pre a").removeClass("can");
			$(".cityAll .next a").addClass("can");
		}
		if (allCityTotalPage == 1) {
			$(".cityAll .next a").removeClass("can");
			$(".cityAll .pre a").removeClass("can");
		}
		if (page >= allCityTotalPage) {
			page = allCityTotalPage;
			$(".cityAll .next a").removeClass("can");
			start = (page - 1) * pa_pageSize;
			end = allCitys.length;
		} else if (page == 1) {
			start = (page - 1) * pa_pageSize;
			end = start + pa_pageSize;
			$(".cityAll .pre a").removeClass("can");
			$(".cityAll .next a").addClass("can");
		} else {
			start = (page - 1) * pa_pageSize;
			end = start + pa_pageSize;
			$(".cityAll .next a").addClass("can");
			$(".cityAll .pre a").addClass("can");
		}
		for (var i = start; i < end; i++) {
			var c_id = allCitys[i].id;
			var cityName = allCitys[i].name.substr(0, 4);
			var li = $('<li><a href="javascript:onclick=viewAllCounties(' + i + ')" id="' + c_id + '">' + cityName + '</a></li>');
			$(".cityAll .list ul").append(li);
		}
		$(".cityAll .list #cityPage1").remove();
		$(".cityAll .list").append("<label id='cityPage1' style='display:none;'>" + page + "</label>");
	}
	function viewAllCounties(i) {
		cityIdAll = allCitys[i].id;
		$("body").data("cAllId", cityIdAll);
		var cityname = $.trim(allCitys[i].name);
		$("body").data("nameOfCityAll", cityname);
		countiesAll = [];
		var j = 0;
		$.each(allAreas,
		function(i, countys) {
			if (countys.cityId == cityIdAll) {
				countiesAll[j++] = countys;
			}
		});
		countyTotalPageAll = Math.ceil(countiesAll.length / pa_pageSize);
		$(".provinceCityAll").find(".tabs").find("a").removeClass("current");
		$(".provinceCityAll .tabs").find("#countyAll").addClass("current");
		$(".con .cityAll .list a").removeClass("current");
		$(".con .cityAll .list a[id='" + cityIdAll + "']").addClass("current");
		$(".provinceCityAll").find(".con").children().hide();
		$(".provinceCityAll").find(".con").find(".countyAll").show();
		allCountyPage(1);
	}
	function allCountyPage(page) {
		var nameOfProvince = $("body").data("pAllName");
		var cityCurrentName = $("body").data("nameOfCityAll");
		$("input.current2").removeClass("iGrays");
		$("input.current2").val(nameOfProvince + "-" + cityCurrentName);
		var isChange = $("input.current2").attr("isChange");
		if (isChange === 'true') {
			$("input.current2").trigger("change");
		}
		$(".countyAll .list ul li").remove();
		if (page == 1) {
			$(".countyAll .pre a").removeClass("can");
		} else {
			$(".countyAll .pre a").addClass("can");
		}
		var start;
		var end;
		if (page <= 1) {
			page = 1;
			$(".countyAll .pre a").removeClass("can");
			$(".countyAll .next a").addClass("can");
		}
		if (countyTotalPageAll == 1) {
			$(".countyAll .next a").removeClass("can");
			$(".countyAll .pre a").removeClass("can");
		}
		if (page >= countyTotalPageAll) {
			page = countyTotalPageAll;
			$(".countyAll .next a").removeClass("can");
			start = (page - 1) * pa_pageSize;
			end = countiesAll.length;
		} else if (page == 1) {
			start = (page - 1) * pa_pageSize;
			end = start + pa_pageSize;
			$(".countyAll .pre a").removeClass("can");
			$(".countyAll .next a").addClass("can");
		} else {
			start = (page - 1) * pa_pageSize;
			end = start + pa_pageSize;
			$(".countyAll .next a").addClass("can");
			$(".countyAll .pre a").addClass("can");
		}
		for (var i = start; i < end; i++) {
			var c_id = countiesAll[i].id;
			var countyName = countiesAll[i].areaName.substr(0, 4);;
			var li = $('<li><a href="javascript:onclick=addrInputAll(' + i + ')" id="' + c_id + '">' + countyName + '</a></li>');
			$(".countyAll .list ul").append(li);
		}
		$(".countyAll .list #countyPage1").remove();
		$(".countyAll .list").append("<label id='countyPage1' style='display:none;'>" + page + "</label>");
	}
	function addrInputAll(i) {
		var countyId = $.trim(countiesAll[i].id);
		$(".con .hotCityAll .list a input").removeClass("current");
		$(".con .hotCityAll .list a input[id='" + cityIdAll + "']").addClass("current");
		$(".con .countyAll .list a").removeClass("current");
		$(".con .countyAll .list a[id='" + countyId + "']").addClass("current");
		allProId = $("body").data("pAllId");
		cityIdAll = $("body").data("cAllId");
		var p = null;
		var pId = null;
		$.each(allProvinces,
		function(i, province) {
			if (province.id == allProId) {
				p = province.provinceName;
				pId = province.id;
				return false;
			}
		});
		var c = null;
		var cId = null;
		$.each(allCities,
		function(i, city) {
			if (city.id == cityIdAll) {
				c = city.name;
				cId = city.id;
				return false;
			}
		});
		var a = null;
		var aId = null;
		$.each(countiesAll,
		function(i, county) {
			if (county.id == countyId) {
				a = county.areaName;
				aId = county.id;
				return false;
			}
		});
		var nameValue = $("input.current2");
		nameValue.removeClass("iGrays");
		$(".provinceCityAll").hide();
		var rtn = p + "-" + c + "-" + a;
		var ntn = pId + "-" + cId + "-" + aId;
		$("input.current2").val(rtn);
		$("input.current2").attr("alt",ntn);
		$(".backifname").hide();
		var isChange = $("input.current2").attr("isChange");
		if (isChange === 'true') {
			$("input.current2").trigger("change");
		}
	}
	function hotCityAddrInputAll(proCityId) {
		allProId = proCityId.split(",")[0];
		cityIdAll = proCityId.split(",")[1];
		var cityCurName = proCityId.split(",")[2];
		$("body").data("nameOfCityAll", cityCurName);
		$("body").data("pAllId", allProId);
		$("body").data("cAllId", cityIdAll);
		$.each(allProvinces,
		function(i, pro) {
			if (pro.id == allProId) {
				$("body").data("pAllName", pro.provinceName);
			}
		});
		countiesAll = [];
		var j = 0;
		$.each(allAreas,
		function(i, county) {
			if (county.cityId == cityIdAll) {
				countiesAll[j++] = county;
			}
		});
		countyTotalPageAll = Math.ceil(countiesAll.length / pa_pageSize);
		$(".provinceCityAll").find(".tabs").find("a").removeClass("current");
		$(".provinceCityAll .tabs").find("#countyAll").addClass("current");
		$(".con .cityAll .list a").removeClass("current");
		$(".con .cityAll .list a[id='" + cityIdAll + "']").addClass("current");
		$(".provinceCityAll").find(".con").children().hide();
		$(".provinceCityAll").find(".con").find(".countyAll").show();
		$(".con .provinceAll .list a").removeClass("current");
		allCountyPage(1);
	}
	
	(function() {
		$(document).on("click",".proCitySelAll",function(event) {
			if(!$(this).hasClass("disable-input")){
				if ($("body").data("CitysAll") == null) {
					sendAllCitiesAjax();
				}else{
					var data = $("body").data("CitysAll");
					allCities = data.cities;
					viewAllHotCities();
				}
				$(this).select();
				$(".provinceCity").hide();
				$(".provinceCityAll").hide();
				$("#dimCityQuery").hide();
				var o2 = $(this).offset();
				var l2 = o2.left;
				var t2 = o2.top;
				var h2 = $(this).height();
				$(".provinceCityAll").css("top", t2 + h2 - 1).css("left", l2);
				$(".provinceCityAll").toggle();
				$(".provinceCityAll").click(function(event) {
					event.stopPropagation();
				});
				event.stopPropagation();
				$("html").click(function() {
					$(".provinceCityAll").hide();
				});
				$("input.proCitySelAll").removeClass("current2");
				$(this).addClass("current2");
				$(".provinceCityAll").find(".tabs").find("a").removeClass("current");
				$(".provinceCityAll").find(".tabs").find("a[tb=hotCityAll]").addClass("current");
				$(".provinceCityAll").find(".con").children().hide();
				$(".provinceCityAll").find(".con").find(".hotCityAll").show();
				if ($("body").data("allProvinces") == null) {
					sendAllProvinceAjax();
				}else{
					allProvinces = $("body").data("allProvinces");
					provinceAllTotalPage = Math.ceil(allProvinces.length / pa_pageSize);
					viewAllProvince(1);
				}
				if ($("body").data("allCountys") == null) {
					sendAllCountiesAjax();
				}else{
					allAreas = $("body").data("allCountys");
				}
				$(".provinceCityAll").find(".tabs").find("a").click(function() {
					if ($(this).attr("tb") == "cityAll" && $(".provinceAll .list .current").val() == null) {
						return;
					};
					if ($(this).attr("tb") == "countyAll" && $(".cityAll .list .current").val() == null && $(".hotCityAll .list .current").val() == null) {
						return;
					};
					$(".provinceCityAll").find(".tabs").find("a").removeClass("current");
					$(this).addClass("current");
					var tb = $(this).attr("tb");
					$(".provinceCityAll").find(".con").children().hide();
					$(".provinceCityAll").find(".con").find("." + tb).show();
				});
			}
		});
	})(); 
	(function() {
		$(".proCitySelAll_Img").click(function(event) {
			event.stopPropagation();
			$(this).prev().trigger("click");
		});
	})();
	function wrongMsg(object, msg) {
		$(".wrongMsg").text(msg);
		object.addClass("wrong");
	}
	(function() {
		var picNum = $("div.flashPic img").size();
		var isNum = 0;
		var str = [];
		var imgDiv = $("div.flashPic");
		var $div = $("div.picNum");
		imgDiv.find("img").hide().eq(0).show();
		for (var i = 0; i < picNum; i++) {
			str[i] = "<a href='javascript:'>" + (i + 1) + "</a>";
		}
		$div.html(str.join(""));
		$div.find("a:eq(0)").addClass("on");
		function MovePic() {
			if ((isNum + 1) >= picNum) {
				isNum = 0;
			}
			 else {
				isNum = isNum + 1;
			}
			imgDiv.find("img").hide().eq(isNum).fadeIn(500);
			$div.find("a").removeClass("on").eq(isNum).addClass("on");
		}
		var setFn = setInterval(MovePic, 4000);
		$div.find("a").click(function() {
			clearInterval(setFn);
			var j = $(this).index();
			$div.find("a").removeClass("on").siblings().eq(j).addClass("on");
			imgDiv.find("img").hide();
			imgDiv.find("img").eq(j).fadeIn(500);
			isNum = j;
			setFn = setInterval(MovePic, 4000);
		});
	})();
</script>